/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.txweb.view;

import com.jspx.boot.environment.Environment;
import com.jspx.sioc.annotation.Ref;
import com.jspx.txweb.annotation.HttpMethod;
import com.jspx.txweb.annotation.Safety;
import com.jspx.txweb.dao.GenericDAO;
import com.jspx.txweb.support.ActionSupport;
import com.jspx.utils.ClassUtil;
import com.jspx.utils.StringUtil;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: chenYuan
 * Date: 12-2-4
 * Time: 下午10:10
 *
 */
@HttpMethod(caption = "默认浏览")
public class GenericView extends ActionSupport {
    private String namespace = StringUtil.empty;
    private String className = StringUtil.empty;
    private String turnPage = StringUtil.empty;
    private int count = 0;
    private long id = 0;
    private long uid = 0;
    private int currentPage = 0;
    private String term = StringUtil.empty;
    private String sort = "sortType:D;fileType:A";
    private String field = StringUtil.empty;
    private String find = StringUtil.empty;
    private String turnPageFile = "turnpage.ftl";

    protected GenericDAO genericDAO;
    @Ref(name = Environment.genericDAO)
    public void setGenericDAO(GenericDAO genericDAO)
    {
        this.genericDAO = genericDAO;
    }

    public String getNamespace() {
        return namespace;
    }

    @Safety
    public void setNamespace(String namespace) {
        this.namespace = namespace;
    }

    public String getClassName() {
        return className;
    }

    @Safety
    public void setClassName(String className) {
        this.className = className;
    }

    public String getTurnPage() {
        return turnPage;
    }

    @Safety(request = false)
    public void setTurnPage(String turnPage) {
        this.turnPage = turnPage;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public String getTerm() {
        return term;
    }

    @Safety
    public void setTerm(String term) {
        this.term = term;
    }

    public String getSort() {
        return sort;
    }

    @Safety
    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getField() {
        return field;
    }
    @Safety
    public void setField(String field) {
        this.field = field;
    }

    public String getFind() {
        return find;
    }

    @Safety
    public void setFind(String find) {
        this.find = find;
    }

    public String getTurnPageFile() {
        return turnPageFile;
    }

    @Safety
    public void setTurnPageFile(String turnPageFile) {
        this.turnPageFile = turnPageFile;
    }

    public List getList() throws Exception
    {
        return genericDAO.getList(ClassUtil.loadClass(className), field,find, getTerm(),uid,  sort, getCurrentPage(), getCount(),false);
    }

    public long getTotalCount() throws Exception
    {
        return genericDAO.getCount(ClassUtil.loadClass(className), field,find, getTerm(),uid);
    }
}